<?php
/**
 * Created by PhpStorm.
 * User: gaochaolyf
 * Date: 16/5/18
 * Time: 下午2:05
 */

namespace api\Model;

use Think\Model;

class DidiEntityModel extends Model
{
    function __construct() {
        $this->model = M('DidiEntity');
    }

    public function getDidiList($field = array('*'), $condition = array(), $page = 1, $pergage = 10, $order = 'did DESC') {
       // $data = $this->model->join('mcf_order_entity on mcf_order_entity.order_id = mcf_didi_entity.order_id')->where($condition)->field($field)->page($page, $pergage)->order($order)->select();

        //print_r($condition);die;
        $data=M('DidiEntity d')->join('mcf_order_entity o on d.order_id = o.order_id')->where($condition)->field($field)->page($page, $pergage)->order($order)->select();

        foreach ($data as $key=>$value){
           $data[$key]['allnum'] = $this->model->where($condition)->count();
       }
        $data = $data ? $data : array();

        return $data;
    }

    public function getOneDidi($field = array('*'), $condition = array()) {
        $data = $this->model->where($condition)->field($field)->find();
        $data = $data ? $data : array();

        return $data;
    }

    public function getByDid($did = 0, $field = array('*')) {
        $data = $this->model->where(array('did' => $did))->field($field)->find();
        $data = $data ? $data : array();

        return $data;
    }

    public function addOneDidi($param = array()) {

        //print_r($param);die;
        $insert_id = $this->model->data($param)->add();

        return $insert_id;
    }

    public function updateOneDidi($param = array(), $condition = array()) {
        $affected = $this->model->where($condition)->setField($param);

        return $affected;
    }

    public function getCountByInteger($integer_id = 0) {
        $count = $this->model->where(array('integer_id' => $integer_id, 'status' => 2))->count();
        return $count;
    }
}